package com.wind.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wind.mapper.*;
import com.wind.model.*;
import com.wind.service.KylinService;
import com.wind.util.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: KylinServiceImpl
 * @Description: TODO
 * @Author: wind
 * @Date: 2018/8/10 上午10:32
 */
@Service
public class KylinServiceImpl implements KylinService {

    @Resource
    private FileDetailMapper fileDetailMapper;
    @Resource
    private LeoResultMapper leoResultMapper;
    @Resource
    private SateOrbitMapper sateOrbitMapper;
    @Resource
    private TaskUserMapper taskUserMapper;
    @Resource
    private TaskUserTargetMapper taskUserTargetMapper;
    @Resource
    private TaskAnalysisQuenceMapper taskAnalysisQuenceMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return fileDetailMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(FileDetail record) {
        return fileDetailMapper.insert(record);
    }


    @Override
    public SateOrbitWithBLOBs selectLastOne(String userTaskGuid)
    {
        return  sateOrbitMapper.selectLastOne(userTaskGuid);
    }

    @Override
    public TaskAnalysisQuence selectTaskAnalysisQuenceByCreatTime()
    {
        return  taskAnalysisQuenceMapper.selectTaskAnalysisQuenceByCreatTime();
    }

    @Override
    public TaskUser selectTaskUserByPrimaryKey(String userTaskGuid)
    {
        return  taskUserMapper.selectByPrimaryKey(userTaskGuid);
    }

    @Override
    public int insertLeoResult(LeoResult record) {
        return leoResultMapper.insert(record);
    }


    @Override
    public int insertSelective(FileDetail record) {
        return fileDetailMapper.insertSelective(record);
    }

    @Override
    public FileDetail selectByPrimaryKey(Integer id) {
        return fileDetailMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(FileDetail record) {
        return fileDetailMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(FileDetail record) {
        return fileDetailMapper.updateByPrimaryKey(record);
    }

    @Override
    @Transactional(readOnly = false,rollbackFor = Exception.class)
    public void deleteAllFileDetail() {
        fileDetailMapper.deleteAllFileDetail();
    }

    @Override
    @Transactional(readOnly = false,rollbackFor = Exception.class)
    public void insertBatchFileDetail(List<FileDetail> fdList) {
        fileDetailMapper.insertBatchFileDetail(fdList);
    }


    @Override
    public Page<FileDetail> getFileDetailPage(String fileName, Integer page, Integer limit) {
        if(page == null){
            page = 1;
            }
        if(page <= 0){
            page = 1;
        }
        if(limit == null){
            limit = 30;
            }
        //1、设置分页信息，包括当前页数和每页显示的总计数
        PageHelper.startPage(page, limit);
        //2、执行查询
        List<FileDetail> list = fileDetailMapper.selectByFileName(fileName);
        //3、获取分页查询后的数据
        PageInfo<FileDetail> pageInfo = new PageInfo<FileDetail>(list);
        //4、封装需要返回的分页实体
        Page<FileDetail> result = new Page<FileDetail>();
        //设置获取到的总记录数total：
        result.setTotalRecord(pageInfo.getTotal());
        //设置数据集合rows：
        result.setResults(list);
        result.setCode("0");
        result.setMsg("ok");
        return result;
    }
}